package org.orz.story.pms.biz.web.admin;

import groovy.util.logging.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.orz.cloud.common.result.ResultDTO;
import org.orz.cloud.common.result.ResultPageDTO;
import org.orz.story.pms.biz.model.req.*;
import org.orz.story.pms.biz.model.resp.ListApiByPermissionIdResp;
import org.orz.story.pms.biz.model.resp.ListApiInfoWithPermitStatusResp;
import org.orz.story.pms.biz.model.resp.ListApiInfoResp;
import org.orz.story.pms.biz.service.PmsApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/api")
@Slf4j
@Api(tags = "管理端api管理接口")
public class AdminApiController {
    @Autowired
    private PmsApiService pmsApiService;

    @ApiOperation("分页查询接口信息")
    @PostMapping("listApiInfo")
    public ResultPageDTO<ListApiInfoResp> listApiInfo(@RequestBody ListApiInfoReq req){
        return ResultPageDTO.restPage(pmsApiService.listApiInfo(req), ListApiInfoResp.class);
    }

    @ApiOperation("根据权限id查询已经分配的接口集合")
    @PostMapping("listApiByPermissionId")
    public ResultPageDTO<ListApiByPermissionIdResp> listApiByPermissionId(@RequestBody ListApiByPermissionIdReq req){
        return ResultPageDTO.restPage(pmsApiService.listApiByPermissionId(req), ListApiByPermissionIdResp.class);
    }

    @ApiOperation("根据权限id查询接口集合")
    @PostMapping("listApiInfoWithPermitStatus")
    public ResultPageDTO<ListApiInfoWithPermitStatusResp> listApiInfoWithPermitStatus(@RequestBody ListApiInfoWithPermitStatusReq req){
        return ResultPageDTO.restPage(pmsApiService.listApiInfoWithPermitStatus(req));
    }

    @ApiOperation("新增接口信息")
    @PostMapping("addApi")
    public ResultDTO<Boolean> addApi(@RequestBody AddApiReq req){
        pmsApiService.addApi(req);
        return ResultDTO.success();
    }

    @ApiOperation("修改接口信息")
    @PostMapping("updateApi")
    public ResultDTO<Boolean> updateApi(@RequestBody UpdateApiReq req){
        pmsApiService.updateApi(req);
        return ResultDTO.success();
    }

    @ApiOperation("删除接口")
    @PostMapping("deleteApi")
    public ResultDTO<Boolean> deleteApi(@RequestBody DeleteApiReq req){
        pmsApiService.deleteApi(req);
        return ResultDTO.success();
    }

}
